/***************************************************************************
 *   Copyright (C) 2008/2009 by Philipp Müller <philipp.mueller@gmx.de>    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA          *
 ***************************************************************************/

#ifndef WIDGETPLAYVIDEO_H
#define WIDGETPLAYVIDEO_H

#include <QWidget>
#include <QLabel>
#include <QLineEdit>
#include <QToolBar>
#include <QProgressBar>
#include <phonon/phononnamespace.h>
#include <phonon/mediaobject.h>
#include <phonon/seekslider.h>
#include <phonon/volumeslider.h>

#include "vdrthread.h"
#include "iostream.h"
#include "widgetvideo.h"
#include "widgetosd.h"
#include "widgetrecordingslider.h"


class MainWindow;

/**
    @author Philipp Müller <philipp.mueller@gmx.de>
*/

class WidgetPlayVideo : public QWidget
{
        Q_OBJECT

    public:
        WidgetPlayVideo( MainWindow *mainWindow, QWidget *parent = 0 );
        ~WidgetPlayVideo();

        void initWidgetPlayVideo();
        void handleKeyPressEvent( QKeyEvent *event );

        WidgetOsd* osd() { return m_osd; };

        Phonon::MediaObject* mediaObject() { return m_mediaObject; };

    signals:
        void hideWindowTV( bool reloadChannellist = false );
        void hideWindowRecording( bool reloadRecordingslist = false );
        void hideWindowMedia( bool reloadMedialist = false );
        void setFullScreen( bool fullScreen = true );
        void recordingTick( qint64 tick );

    public slots:
        /** Stops playing video and recordings at mediaObject */
        void stopPlayVideo();

        /** Sets the new position to pos in seconds */
        void recordingSetNewPosition( quint32 posTime );

    private slots:
        void playTV();
        void playRecording();
        void playMedia();
        void stateChanged( Phonon::State newState, Phonon::State oldState );
        void updateMetaData();
        void fullScreenAction();
#ifndef QTVOMP_GSTREAMER
        void emitManualTick();
#endif
        void bufferStatus( int percentage );

    private:
        void keyPressEvent( QKeyEvent *event );
        void switchChannel();
        void setupActions();
        void setupUi();
        void exit();

        WidgetVideo           *m_videoWidget;
        Phonon::MediaObject   *m_mediaObject;
        Phonon::SeekSlider    *m_seekSlider;
        WidgetRecordingSlider *m_recordingSlider;
        Phonon::VolumeSlider  *m_volumeSlider;
        QWidget               *m_metaDataWidget;
        WidgetOsd             *m_osd;
        QLabel                *m_channelNotAvailable;
        QProgressBar          *m_progressBar;

        QToolBar *m_mediaButtonBar;
        QToolBar *m_fullScreenBar;
        QAction  *m_playAction;
        QAction  *m_pauseAction;
        QAction  *m_stopAction;
        QAction  *m_fullScreen;

        QLineEdit *m_titelText;
        QLineEdit *m_artistText;
        QLineEdit *m_albumText;
        QLineEdit *m_yearText;
        QLineEdit *m_genreText;
        QLineEdit *m_trackText;
        QLineEdit *m_descriptionText;


        MainWindow *m_mainWindow;
        IOStream   *m_ioStream;
        bool        m_exit;
        bool        m_switchChannel;
#ifndef QTVOMP_GSTREAMER
        bool        m_jumpRecording;
        QTimer     *m_tickTimer;
#endif
};

#endif
